<?php
include("utils.php");

if($_SESSION['siteuserId']==""){
    header("location:index.php");
}
if($_SESSION['langname']==""){
    $language_url="languages/"."english".'/sell_website_add_language.php';
}
else{
    $language_url="languages/".$_SESSION['langname'].'/sell_website_add_language.php';
}
include("$language_url");

if(isset ($_POST['save'])){
    if(isset ($_POST['textSave'])){
    $updateAdSql = "insert into adspace_details set adspaceId='".$adspaceId."',
                                                adspaceIdMd='".$md_no."',
                                                adspaceType='".$_POST['adspace_type']."',
                                                adSize='".$_POST['size']."',
                                                fontType='".$_POST['font_type']."',
                                                backgroundColor='".$_POST['background_color']."',
                                                noOfTextAd='".$_POST['cell_count']."',
                                                headerColor='".$_POST['title_color']."',
                                                thumbOrientation='".$_POST['alignment']."',
                                                bodyColor='".$_POST['description_color']."',
                                                allowNetwork='".$netVal."' ";
    echo $updateAdSql;
    echo '<br/>';
    echo $_POST['ed'];
    main_content("main();");
    }
}
else
{
    main_content("main();");
}

function saveInfoWeb()
{	
    if($_SESSION['languageId']!="")
    {
        $languageId=$_SESSION['languageId'];
    }
    else
    {
        $languageId='1';
    }
    if($_POST['site_name']==''){
        $GLOBALS['msg']="Site name can not blank";
    }
    elseif($_POST['destinationUrl']==''){
        $GLOBALS['msg']="Destination URL can not blank";
    }
    else{
       $query="update ".SITEMASTER." set
                adSiteName='".$_POST['site_name']."',
                adSiteUrl='".$_POST['destinationUrl']."',
                adcategoryId='".$_POST['adcategory']."',
                siteDescription='".$_POST['description']."' ";
        $query.=" where adsiteId='".$_REQUEST['sid']."' ";

        mysql_query($query);
        $GLOBALS['msg']="Successfully update your website";
    }
    //     $query="update ".SITEMASTER." set
    //            adSiteName='".$_POST['site_name']."',
    //            adSiteType='".$_POST['site_type']."',
    //            adSiteUrl='".$_POST['destinationUrl']."',
    //            adcategoryId='".$_POST['adcategory']."',
    //            siteDescription='".$_POST['description']."' ";
    main_content("main();");
}

function saveTextAds(){
    
}

function main()
{
    $sql="select * from ".SITEMASTER." where adsiteId='".$_REQUEST['sid']."'";
    $rec=mysql_fetch_array(mysql_query($sql));
    $sql2 = "select m.*, d.adspacetype from adspace_master m
            inner join (select adSpaceId, adspaceType from adspace_details) d
            on m.adspaceid = d.adspaceid
            where m.adsiteid='".$_REQUEST['sid']."' and userid='".$_SESSION['siteuserId']."'";
    $rec2 = mysql_fetch_array(mysql_query($sql2));


//Get current URL
//function curPageURL() {
//    $pageURL = 'http';
//    if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
//        $pageURL .= "://";
//    if ($_SERVER["SERVER_PORT"] != "80") {
//        $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
//    } else {
//        $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
//    }
//    return $pageURL;
//}
?>
<script type="text/javascript">
function show_text()
{
    document.getElementById('link_url_lp_div').style.display='';
    document.getElementById('link_url_existing_div').style.display='none';
}
function hide_text()
{
    document.getElementById('link_url_lp_div').style.display='none';
    document.getElementById('link_url_existing_div').style.display='';
}

function changeValue(strValue, strLength, countId) {
    if (strValue.length <= strLength) {
        if (strValue != null) {
            document.getElementById(countId).innerHTML = (strLength - strValue.length);
            if (countId == 'tagsCount' && (strValue.indexOf('"') >= 0 || strValue.indexOf("'") >= 0 || strValue.indexOf("|") >= 0 || strValue.indexOf("\\") >= 0)) {
                var message = "Invalid tag, please re-enter tags without |, \', \", \\ in it.";
                alert(message);
            }
        }
    }
    else {
        document.getElementById(countId).innerHTML = "<span style=\"color:red\"><?php echo TOO_CHARACTERS_DESC; ?></span>";
    }
}
</script>
<!--<link rel="stylesheet" href="style/ui.tabs.css" type="text/css">
<script type="text/javascript" src="JavaScripts/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="JavaScripts/ui.core.js"></script>
<script type="text/javascript" src="JavaScripts/ui.tabs.js"></script>
<script type="text/javascript">
    jQuery(function() {
        jQuery('#editWebsite > ul').tabs({ selected: 1 });
    });
</script>-->
<h1><?php echo REGISTER_TXT_EDIT;?></h1>
<table width="80%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" align="center">
    <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
    <td valign="top"></td>
    <td valign="top">
        <table width="98%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td valign="top">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                <td width="11"><img src="images/PinkBorderTopLeft.jpg" alt="" width="11" height="11"></td>
                <td class="PinkBoxTopBg"><img src="images/spacer.gif" alt="" width="10" height="11"></td>
                <td width="11"><img src="images/PinkBorderTopRight.jpg" alt="" width="11" height="11"></td>
                </tr>
                </table>
            </td>
        </tr>
        <tr>
        <td class="PinkTwosideBorder" valign="top">
            <table>
                <tr>
                    <td>
                        <form name="frm1" method="post" action="">
                        <input name="ed" type="hidden" value="1">
                        <input type="submit" value="Site Info">
                        </form>
                    </td>
                    <td>
                        <form name="frm2" method="post" action="">
                        <input name="ed" type="hidden" value="2">
                        <input type="submit" value="Ad Specs">
                        </form>
                    </td>
                    <td>
                        <form name="frm3" method="post" action="">
                        <input name="ed" type="hidden" value="3">
                        <input type="submit" value="Get Ad Code">
                        </form>
                    </td>
                </tr>
            </table>
            <div id="editWeb">
                <?php
                    if(isset ($_POST['ed'])){
                        switch ($_POST['ed']){
                            case '1':
                                include_once 'editWebInfo.php';
                                break;
                            case '2':
                                include_once 'editTextAdSpace.php';
                                break;
                            case '3':
                                include_once 'editGetCode.php';
                                break;
                            default:
                                include_once 'editWebInfo.php';
                                break;
                        }
                    }
                    else{
                        include_once 'editWebInfo.php';
                    }
                ?>
            </div>

            </td>
        </tr>
        <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
        <td width="11"><img src="images/PinkBorderBottomLeft.jpg" alt="" width="11" height="11"></td>
        <td class="PinkBoxBottomBg"><img src="images/spacer.gif" alt="" width="10" height="11"></td>
        <td width="11"><img src="images/PinkBorderBottomRight.jpg" alt="" width="11" height="11"></td>
        </tr>
        </table></td>
        </tr>
        </table>
    </td>
    <td>&nbsp;</td>
    </tr>
    </table>
</td>
</tr>
</table>
<?php
}
?>
<!--###############################################-->
<!--BEGIN Tabs-->
<!--<div id="editWebsite" style="width: 100%;">
    <ul>
        <li><a href="#infoWeb"><span>Site Info &sup1;</span></a></li>
        <li><a href="#adSpaceWeb"><span>Ad Specs &sup2;</span></a></li>
        <li><a href="#adCodeWeb"><span>Get Ad Code &sup3;</span></a></li>
    </ul>
    <div id="infoWeb">
        <!--BEGIN Edit Web Description-->
        <!--<form name="web_add" method="POST" action="">
        <input type="hidden" name="mode" value="saveInfoWeb">
        <table class="center" cellspacing="0" cellpadding="0">
        <tr>
        <td align="left" valign="top">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td>
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
            <td width="154" valign="top">&nbsp;</td>
            <td valign="top">
                <table border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td height="30" colspan="5" align="center" style="padding-top:20px;"><font color="red">
                        <?php //echo $GLOBALS['msg'];?></font>
                    </td>
                </tr>
                <tr>
                    <td width="100" height="50" colspan="5" align="center" valign="middle" class="font-12 black advertise_tableTxt">
                        <?php //echo REGISTER_DESC;?>
                    </td>
                </tr>
                <tr>
                    <td width="100" height="30">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td width="3"><img src="images/FormNameBoxLeft.jpg" alt="" width="3" height="18"></td>
                            <td class="FormNameBoxBg"><?php //echo SITENAME;?>:</td>
                            <td width="13"><img src="images/FormNameBoxRight.jpg" alt="" width="13" height="18"></td>
                        </tr>
                        </table>
                    </td>
                    <td width="14">&nbsp;</td>
                    <td><input name="site_name" type="text" class="InputBox" id="siteName" value="<?php //echo $rec['adSiteName'];?>"></td>
                    <td width="11">&nbsp;</td>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td height="30">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td width="3"><img src="images/FormNameBoxLeft.jpg" alt="" width="3" height="18"></td>
                            <td class="FormNameBoxBg">Site URL:</td>
                            <td width="13"><img src="images/FormNameBoxRight.jpg" alt="" width="13" height="18"></td>
                        </tr>
                        </table>
                    </td>
                    <td>&nbsp;</td>
                    <td>
                        <table>
                        <tr>
                        <td colspan="2" class="font-12 black advertise_tableTxt">
                            <input name="destinationUrl" id="destinationUrl" value="<?php echo $rec['adSiteUrl'];?>" type="text" class="InputBox">
                        </td>
                        </tr>
                        </table>
                    </td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td height="30">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td width="3"><img src="images/FormNameBoxLeft.jpg" alt="" width="3" height="18"></td>
                            <td class="FormNameBoxBg">Category:</td>
                            <td width="13"><img src="images/FormNameBoxRight.jpg" alt="" width="13" height="18"></td>
                        </tr>
                        </table>
                    </td>
                    <td>&nbsp;</td>
                    <td>
                        <select id="adcategory" name="adcategory" class="InputBox">
                        <option value="">--select--</option>
                        <?
                            //$query_category=mysql_query("select * from ".CATEGORIES." where langId='1'");
                            //while($res_cat= mysql_fetch_array($query_category)){
                        ?>
                            <option value="<? //echo $res_cat['adcategoryId']?>" <?php //if($res_cat['adcategoryId']==$rec['adcategoryId']) echo "selected";?>> <?php //echo stripslashes($res_cat['categoryName']);?></option>
                        <?
                            //}
                        ?>
                        </select>
                    </td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td height="30">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td width="3"><img src="images/FormNameBoxLeft.jpg" alt="" width="3" height="18"></td>
                            <td class="FormNameBoxBg" nowrap="true">Site Description:</td>
                            <td width="13"><img src="images/FormNameBoxRight.jpg" alt="" width="13" height="18"></td>
                        </tr>
                        </table>
                    </td>
                    <td>&nbsp;</td>
                    <td valign="middle">
                        <textarea id="description" name="description" cols="42" rows="5" class="InputtextArea" onkeyup="javascript:changeValue(this.value, 255, 'descriptionCount');"><?php echo $rec['siteDescription'];?></textarea>
                        &nbsp;<font class="BlackContent">(Characters left:</font><span id="descriptionCount" class="BlackContent">255</span><font class="BlackContent"> )</font>
                    </td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                <td colspan="5" style="text-align: center; padding-top: 10px;">
                    <input name="button3" type="submit" class="SubmitInputButton" id="button3" value="Save" style="width: 60px;">
                </td>
                </tr>
                </table>
            </td>
            </tr>
            </table>
        </td></tr>
        </table>
        </td>
        </tr>
        </table>
        </form>
        <!--END Edit Web Description-->
    <!--</div>
    <div id="adSpaceWeb">
        <!--BEGIN Edit Ads Space-->
        <!--<link rel="stylesheet" href="css/adspace.css" type="text/css">
        <link rel="stylesheet" href="css/style_002.css" type="text/css">
        <script type="text/javascript" language="javascript" src="JavaScripts/common.js"></script>
        <script type="text/javascript" language="javascript" src="JavaScripts/popup-layer.js"></script>
        <script type="text/javascript" language="javascript" src="JavaScripts/category-list.js"></script>
        <script type="text/javascript" language="javascript" src="JavaScripts/cover.js"></script>
        <div id="colorlayer" onMouseOver="javascript:enterColorPalette()" onMouseOut="javascript:leaveColorPalette()" class="drag" style="visibility: hidden; width: 204px; height: 142px; position: absolute; z-index: 4; left: 488px; top: 635px;">
            <table bgcolor="#ffffff" border="0" cellpadding="1" cellspacing="2" width="100%">
            <tbody>
                <tr>
                    <td id="selectedcolor" bgcolor="#ff8080" width="12%"></td>
                    <td id="colorcode" align="center" width="75%"><b>#FF8080</b></td>
                    <td width="12%">
                        <div id="transparent" style="cursor: pointer; visibility: hidden;">
                            <img alt="" src="images/transparent.gif" onMouseOver="javascript:onTransparent();" onClick="javascript:onClickTransparent();preview();">
                        </div>
                    </td>
                </tr>
            </tbody>
            </table>
            <table id="colortable" style="border: 1px solid rgb(127, 157, 185); cursor: pointer; height: 115px;" bgcolor="#ffffff" border="0" cellpadding="1" cellspacing="2" width="100%">
            <tbody>
            <tr><td bgcolor="#ff8080" height="17"></td><td bgcolor="#ffff80" height="17"></td><td bgcolor="#80ff80" height="17"></td><td bgcolor="#00ff80" height="17"></td><td bgcolor="#80ffff" height="17"></td><td bgcolor="#0080ff" height="17"></td><td bgcolor="#ff80c0" height="17"></td><td bgcolor="#ff80ff" height="17"></td></tr><tr><td bgcolor="#ff0000" height="17"></td><td bgcolor="#ffff00" height="17"></td><td bgcolor="#80ff00" height="17"></td><td bgcolor="#00ff40" height="17"></td><td bgcolor="#00ffff" height="17"></td><td bgcolor="#0080c0" height="17"></td><td bgcolor="#8080c0" height="17"></td><td bgcolor="#ff00ff" height="17"></td></tr><tr><td bgcolor="#804040" height="17"></td><td bgcolor="#ff8040" height="17"></td><td bgcolor="#00ff00" height="17"></td><td bgcolor="#008080" height="17"></td><td bgcolor="#004080" height="17"></td><td bgcolor="#8080ff" height="17"></td><td bgcolor="#800040" height="17"></td><td bgcolor="#ff0080" height="17"></td></tr><tr><td bgcolor="#800000" height="17"></td><td bgcolor="#ff8000" height="17"></td><td bgcolor="#008000" height="17"></td><td bgcolor="#008040" height="17"></td><td bgcolor="#0000ff" height="17"></td><td bgcolor="#0000a0" height="17"></td><td bgcolor="#800080" height="17"></td><td bgcolor="#8000ff" height="17"></td></tr><tr><td bgcolor="#400000" height="17"></td><td bgcolor="#804000" height="17"></td><td bgcolor="#004000" height="17"></td><td bgcolor="#004040" height="17"></td><td bgcolor="#000080" height="17"></td><td bgcolor="#000040" height="17"></td><td bgcolor="#400040" height="17"></td><td bgcolor="#400080" height="17"></td></tr><tr><td bgcolor="#000000" height="17"></td><td bgcolor="#808000" height="17"></td><td bgcolor="#808040" height="17"></td><td bgcolor="#808080" height="17"></td><td bgcolor="#408080" height="17"></td><td bgcolor="#c0c0c0" height="17"></td><td bgcolor="#400040" height="17"></td><td bgcolor="#ffffff" height="17"></td></tr>
            </tbody>
            </table>
            <iframe src="selling-basic-adspace-add_files/blank_003.html" style="position: absolute; visibility: inherit; top: 0px; left: 0px; width: 204px; height: 142px; z-index: -1;" frameborder="0">
            </iframe>
        </div>        
        <form id="basicLayout" action="" method="post" class="tight-layout">
        <input type="hidden" name="mode" value="saveTextAds">
        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="admob-Height">
        <tr>
            <td valign="top" align="center">
                <table border="0" align="center" cellpadding="0" cellspacing="0" class="admob-Height" width="90%">
                <tr>
                <td width="244" valign="top">
                    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="admob-Height">
                    <tr>
                        <td width="14" valign="top">&nbsp;</td>
                        <td valign="top">
                            <table width="100%" border="0" cellpadding="0" cellspacing="0" class="admob-Height">
                            <tr>
                                <td valign="top">
                                <table width="100%" border="0" cellpadding="0" cellspacing="0" class="admob-Height">
                                <tr>
                                <td width="150" height="25"><strong>Ad Space Name:</strong>
                                <script type="text/javascript">
                                //Ajax : load adType form
                                var xmlhttp;
                                function changeForm(obj)
                                {
                                xmlhttp=GetXmlHttpObject();
                                if (xmlhttp==null)
                                {
                                    alert ("Browser does not support HTTP Request");
                                    return;
                                }
                                var url="getAdSpaceInfo.php";
                                url=url+"?id="+obj.value;
                                xmlhttp.onreadystatechange=stateChanged;
                                xmlhttp.open("GET",url,true);
                                xmlhttp.send(null);
                                }

                                function loadjscssfile(filename, filetype){
                                    if (filetype=="js"){ //if filename is a external JavaScript file
                                        var fileref=document.createElement('script');
                                        fileref.setAttribute("type","text/javascript");
                                        fileref.setAttribute("src", filename);
                                    }
                                    else if (filetype=="css"){ //if filename is an external CSS file
                                        var fileref=document.createElement("link");
                                        fileref.setAttribute("rel", "stylesheet");
                                        fileref.setAttribute("type", "text/css");
                                        fileref.setAttribute("href", filename);
                                    }
                                    if (typeof fileref!="undefined")
                                        document.getElementsByTagName("head")[0].appendChild(fileref);
                                }

                                function inc(filename)
                                {
                                    var body = document.getElementsByTagName('body').item(0);
                                    script = document.createElement('script');
                                    script.src = filename;
                                    script.type = 'text/javascript';
                                    body.appendChild(script);
                                }


                                function stateChanged()
                                {
                                    if (xmlhttp.readyState==4 && xmlhttp.status == 200)
                                    {
                                        var rt = xmlhttp.responseText;
                                        document.getElementById("adText").innerHTML = rt;

//                                        var js = rt.replace(/\<script[\w\W]+?\>/i,"").replace(/\<\\script\s*\>/i,"");
//                                        try {
//                                            eval(js);
//                                        }
//                                        catch(err){
//                                            document.getElementById("adText").innerHTML = String(err);
//                                        }

                                        var adtype = document.getElementById('ad_type').value;
                                        switch (adtype) {
                                            case 'text':
                                                var transparent = "TRANSPARENT";

                                                var ns = document.getElementById&&!document.all; //boolean flag for netscape/firefox
                                                var objId; //object id
                                                var selected; //selected color
                                                var onchangeFlag = false;
                                                init();
                                                //Initialize the color table.
                                                function init() {
                                                    var colors = new Array (
                                                        ['#FF8080', '#FFFF80', '#80FF80', '#00FF80', '#80FFFF', '#0080FF', '#FF80C0', '#FF80FF'],
                                                        ['#FF0000', '#FFFF00', '#80FF00', '#00FF40', '#00FFFF', '#0080C0', '#8080C0', '#FF00FF'],
                                                        ['#804040', '#FF8040', '#00FF00', '#008080', '#004080', '#8080FF', '#800040', '#FF0080'],
                                                        ['#800000', '#FF8000', '#008000', '#008040', '#0000FF', '#0000A0', '#800080', '#8000FF'],
                                                        ['#400000', '#804000', '#004000', '#004040', '#000080', '#000040', '#400040', '#400080'],
                                                        ['#000000', '#808000', '#808040', '#808080', '#408080', '#C0C0C0', '#400040', '#FFFFFF']
                                                    );
                                                    var table = document.getElementById("colortable");

                                                    for (itr in colors) {
                                                        var row = table.insertRow(-1);
                                                        for (itd in colors[itr]) {
                                                            var cell = row.insertCell(-1);
                                                            cell.height = 17;
                                                            cell.innerText = "";
                                                            cell.bgColor = colors[itr][itd];

                                                            //when move mouse to a cell, the selected color will changed
                                                            cell.onmouseover = function() {
                                                                var colorcode = document.getElementById("colorcode");
                                                                colorcode.innerHTML = "<b>" + this.bgColor.toUpperCase() + "</b>";
                                                                var selectedcolor = document.getElementById("selectedcolor");
                                                                selectedcolor.bgColor = this.bgColor;
                                                                selected = selectedcolor;
                                                            }
                                                            //when mouse click, the selected color will be assigned to obj
                                                            //and color palette will be closed
                                                            cell.onclick  = function(){
                                                                if (objId != '') {
                                                                    var obj = document.getElementById(objId);
                                                                }
                                                                obj.value = selected.bgColor.toUpperCase();
                                                                if (obj.onchange) {
                                                                    obj.onchange();
                                                                }
                                                                onClickPalette('', null);
                                                                preview();
                                                            };
                                                        }
                                                    }
                                                }


                                                //It is called when mouse over transparent cell
                                                function onTransparent() {
                                                    var colorcode = document.getElementById("colorcode");
                                                    colorcode.innerHTML = "<b>" + transparent + "</b>";
                                                    var selectedcolor = document.getElementById("selectedcolor");
                                                    selectedcolor.bgColor = "Transparent";
                                                }


                                                //It is called when mouseclick on transparent cell
                                                function onClickTransparent() {
                                                    if (objId != '') {
                                                        var obj = document.getElementById(objId);
                                                    }
                                                    obj.value = 'TRANSPARENT';
                                                    onClickPalette('', null);
                                                }

                                                //show or hide the palette
                                                //it also inits table data and div position
                                                function onClickPalette(objid, control, isTran, leftTopDisplay) {
                                                    if (!document.all && onchangeFlag) {
                                                        return;
                                                    }
                                                    var l = 0;
                                                    var t = 0;
                                                    var obj;
                                                    if (objid != '') {
                                                        obj = document.getElementById(objid);
                                                        objId = objid;
                                                    }

                                                    //check that needs the transparent or not
                                                    var transparent = document.getElementById("transparent");
                                                    if (typeof(isTran) != "undefined") {
                                                        transparent.style.visibility = (isTran) ? "inherit" : "hidden";
                                                    }
                                                    else {
                                                        transparent.style.visibility = "hidden";
                                                    }

                                                    //calculate the control position
                                                    if (control != null) {
                                                        controlTop = control.offsetTop + 420;
                                                        controlLeft = control.offsetLeft + 400;
                                                        while(control == control.offsetParent) {
                                                            controlTop += control.offsetTop;
                                                            controlLeft += control.offsetLeft;
                                                        }
                                                    }

                                                    //init div position
                                                    var div = document.getElementById('colorlayer');
                                                    if (leftTopDisplay != null) {
                                                        leftDistance = controlLeft - div.offsetWidth;
                                                        topDistance = controlTop - div.offsetHeight;
                                                        div.style.left = leftDistance + "px";
                                                        div.style.top = topDistance + "px";
                                                    }
                                                    else {
                                                        div.style.left = controlLeft + "px";
                                                        div.style.top = controlTop + "px";
                                                    }

                                                    //init div data
                                                    if (div.style.visibility == 'hidden') {
                                                        var selectedcolor = document.getElementById('selectedcolor');
                                                        selectedcolor.bgColor = obj.value;
                                                        var colorcode = document.getElementById('colorcode');
                                                        colorcode.innerHTML = "<b>" + obj.value.toUpperCase() + "</b>";
                                                    }

                                                    div.style.visibility = (div.style.visibility == 'hidden') ? 'visible' : 'hidden';
                                                }

                                                var inColorPalette = false;
                                                function mousedown() {
                                                    if (!inColorPalette) {
                                                        var div = document.getElementById('colorlayer');
                                                        div.style.visibility = 'hidden';
                                                    }
                                                }

                                                function leaveColorPalette() {
                                                    inColorPalette=false;
                                                }

                                                function enterColorPalette() {
                                                    inColorPalette=true;
                                                }

                                                document.onmousedown = mousedown;
                                                
                                                //controls response
                                                var sz = document.getElementById('size');
                                                var cc = document.getElementById('cellCount');
                                                var cc = document.getElementById('cellCount');
                                                var ft = document.getElementById('fontType');
                                                var bg = document.getElementById('backgroundColor');
                                                var tc = document.getElementById('titleColor');
                                                var dc = document.getElementById('descriptionColor');
                                                var bl = document.getElementById('brokerLinkHide');
                                                //control hidden
                                                var an = document.getElementById('ad_No');
                                                var cc = document.getElementById('cellCount');
                                                var as = document.getElementById('ad_Size');
                                                var af = document.getElementById('ad_fontType');
                                                var ab = document.getElementById('ad_bgColor');
                                                var ah = document.getElementById('ad_hdColor');
                                                var ad = document.getElementById('ad_bdColor');
                                                var al = document.getElementById('ad_hidelink');
                                                //value callback
                                                sz.value = as.value;
                                                cc.value = an.value;
                                                ft.value = af.value;
                                                bg.value = ab.value;
                                                tc.value = ah.value;
                                                dc.value = ad.value;
                                                bl.value = al.value;
                                                //change preview form
                                                //preview();
                                            break;
                                            case 'banner':
                                                //controls response
                                                var sb = document.getElementById('sizeB');
                                                //control hidden
                                                var as = document.getElementById('ad_Size');
                                                var ab = document.getElementById('ad_bgColor');
                                                var ah = document.getElementById('ad_hdColor');
                                                var ad = document.getElementById('ad_bdColor');
                                                var hf = document.getElementById('ad_headFont');
                                                var bf = document.getElementById('ad_bodyFont');
                                                //value callback
                                                sb.value = as.value;
                                                if(ab.value != "" || ah.value != "" || ad.value != ""){
                                                    var tem = document.getElementById('config_appearance');
                                                    var bg = document.getElementById('backgroundColor');
                                                    var tc = document.getElementById('headerColor');
                                                    var dc = document.getElementById('bodyColor');
                                                    var hFont = document.getElementById('headerFontType');
                                                    var bFont = document.getElementById('bodyFontType');
                                                    tem.checked = true;
                                                    setTemplateAppearance(true);
                                                    bg.value = ab.value;
                                                    window.changed = true;changeStyle('color', bg, 'previewBackgroundColor');
                                                    hFont.value = hf.value;
                                                    tc.value = ah.value;
                                                    window.changed = true;changeStyle('color', tc, 'previewHeaderStyle');
                                                    bFont.value = bf.value;
                                                    dc.value = ad.value;
                                                    window.changed = true;changeStyle('color', dc, 'previewBodyStyle');
                                                }
                                                //change preview form
                                                //previewB();window.changed = true;
                                                break;
                                            case 'thumbnail':                                                
                                                //==============================
                                                var headerComponent = document.getElementById('component_header');
                                                if (headerComponent.checked) {
                                                    headerComponent.style.display = 'none';
                                                    headerComponent.nextSibling.style.display = 'none';
                                                }
                                                //==============================
                                                function popupStyleWindow(id,inmode) {
                                                header = document.getElementById('headerContentStyle');
                                                body = document.getElementById('bodyContentStyle');
                                                //borker = document.getElementById('brokerLinkStyle');

                                                //closes all style windows first
                                                header.style.display = 'none';
                                                body.style.display = 'none';
                                                //borker.style.display = 'none';

                                                document.getElementById(id).style.display = '';

                                                window.scrollTo(0, document.getElementById(id).offsetTop);
                                                document.getElementById('insertmode').value = inmode;
                                                }
                                                //==============================
                                                var message_warning_not_allow_network = "Warning! Network ads allow this ad space to always generate revenue, regardless of a direct ad purchase. If you choose to continue, please set your desired sale price for this ad space.";
                                                function checkSelect(obj) {
                                                    if (false == obj.checked) {
                                                        if(!confirm(message_warning_not_allow_network)) {
                                                            obj.checked = true;
                                                        }
                                                    }
                                                }
                                                //==============================
                                                var gtbWidthInputElement = document.getElementById('width');
                                                var gtbHeightInputElement = document.getElementById('height');

                                                var windowOnload = window.onload;
                                                window.onload = function() {
                                                if (windowOnload) {
                                                    windowOnload();
                                                }
                                                enableCustomGtbSize(document.getElementById('customGtbSize'));
                                                }

                                                function enableCustomGtbSize(checkBox) {
                                                if (checkBox.checked) {
                                                gtbWidthInputElement.readOnly = false;
                                                gtbHeightInputElement.readOnly = false;
                                                gtbWidthInputElement.style.color = '#000000';
                                                gtbHeightInputElement.style.color = '#000000';
                                                setSize(gtbWidthInputElement.value, gtbHeightInputElement.value);
                                                }
                                                else {
                                                gtbWidthInputElement.readOnly = true;
                                                gtbHeightInputElement.readOnly = true;
                                                gtbWidthInputElement.style.color = '#808080';
                                                gtbHeightInputElement.style.color = '#808080';
                                                setSize();
                                                }
                                                }
                                                //==============================
                                                
                                                var title = "Header Goes Here";
                                                var titleField = false;
                                                if ((titleField = document.getElementById('headline'))
                                                        && (titleField.type) && ('text' == titleField.type)
                                                        && ('' != titleField.value)) {
                                                    title = titleField.value;
                                                }
                                                var ad = {
                                                    //requestURL: 'show-gallery-entry.php',
                                                    spacer: 'images/spacer.gif',
                                                    //baseURL: '?sid=2d47b082c2e464ec257bb48468c0ddfb',
                                                    space: {
                                                        rating: 'sfw',
                                                        themeId: 1,
                                                        style: {
                                                            cells: 4,
                                                            view: 'horizontal',
                                                            backgroundColor: '#6cdae7',
                                                            imageWidth: 60,
                                                            imageHeight: 60,
                                                            showHandle:  true ,
                                                            showAge:  true ,
                                                            showLocation:  true ,
                                                            showHeadline:  true ,
                                                            showBrokerLink:  true ,
                                                            showImage:  true ,
                                                            showHeader:  true ,
                                                            headStyle: 'fontFamily:Arial;fontSize:15px;color:#000000;textDecoration:none;fontWeight:bold;fontStyle:normal;textAlign:center',
                                                            bodyStyle: 'fontFamily:Arial;fontSize:13px;color:#000000;textDecoration:none;fontWeight:normal;fontStyle:normal;textAlign:center'
                                                //             brokerLinkStyle: 'fontFamily:Arial;fontSize:11px;color:#000000;textDecoration:none;fontWeight:normal;fontStyle:normal;textAlign:center'
                                                        }
                                                    },
                                                    payment: {
                                                        title: title
                                                    },
                                                    location: {
                                                            //latitude: 22.5697,
                                                       // longitude: 88.3697,
                                                        //cityName: 'Calcutta',
                                                            nearbyCities: []
                                                    }
                                                };    
                                                      
                                                var previewer = new GTBPreviewer(ad);
                                                previewer.render();
                                                previewer.style.lastBackgroundColor = previewer.style.background;
                                                previewer.style.head.lastFontColor = previewer.style.head.color;
                                                var warning = document.createElement('div');
                                                warning.style.display = 'none';
                                                previewer.adBlock.parentNode.insertBefore(warning, previewer.adBlock);
                                                var warningMessage = 'The ad cannot be shown correctly because the specified size is too small.';
                                                warning.innerHTML = '<span class="warning">Warning: ' + warningMessage + '</span><br /><br />';
                                                previewer.onOverflow = function (isOverflow) {
                                                    warning.style.display = isOverflow ? 'block' : 'none';
                                                }
                                                previewer.setHeadOnClickHandler(editHeadStyle);
                                                previewer.setBodyOnClickHandler(editBodyStyle);
                                                previewer.setBrokerLinkOnClickHandler(editBrokerLinkStyle);
                                                if (gtbWidthInputElement && gtbWidthInputElement) {
                                                    previewer.onSizeChange = function (width, height) {
                                                        gtbWidthInputElement.value = width;
                                                        gtbHeightInputElement.value = height;
                                                    }
                                                }
                                                function setComponent(checkBox) {
                                                    previewer.setComponent(checkBox.name, checkBox.checked);
                                                }
                                                function setImageSize(size) {
                                                    size = size.toLowerCase().split('x');
                                                    previewer.setImageSize(size[0], size[1]);
                                                }

                                                function setSize(width, height) {
                                                    if (2 != arguments.length) {
                                                        previewer.setSize();
                                                    }
                                                    else {
                                                        previewer.setSize(width, height);
                                                    }
                                                }

                                                function setView() {
                                                    if (document.getElementById('horizontal').checked) {
                                                        previewer.setView(GTBPreviewer.HORIZONTAL);
                                                    }
                                                    else {
                                                        previewer.setView(GTBPreviewer.VERTICAL);
                                                    }
                                                }

                                                function closeStyleWindow(id) {
                                                    document.getElementById(id).style.display='none';
                                                }

                                                function editStyle(self, targetSytleEditId) {
                                                    obj = document.getElementById(targetSytleEditId);

                                                    var top;
                                                    var left;
                                                    var xOffset;
                                                    var yOffset;
                                                    var windowWidth;
                                                    var windowHeight;

                                                    var isIE = document.all ? true : false;

                                                    if (isIE) {
                                                        var htmlObj = document.getElementsByTagName('html')[0];
                                                        left = event.x + htmlObj.scrollLeft;
                                                        top = event.y + htmlObj.scrollTop;
                                                        xOffset = event.x;
                                                        yOffset = event.y;
                                                        windowWidth = htmlObj.clientWidth;
                                                        windowHeight = htmlObj.clientHeight;
                                                    }
                                                    else {
                                                        document.captureEvents(Event.MOUSEMOVE);
                                                        left = self.pageX;
                                                        top = self.pageY;
                                                        xOffset = self.pageX - window.scrollX;
                                                        yOffset = self.pageY - window.scrollY;
                                                        windowWidth = window.innerWidth - 20;
                                                        windowHeight = window.innerHeight;
                                                    }
                                                    obj.style.top = top + "px";
                                                    obj.style.left = left + "px";
                                                    document.getElementById("headerContentStyle").style.display = "none";
                                                    document.getElementById("bodyContentStyle").style.display = "none";
                                                    document.getElementById("brokerLinkStyle").style.display = "none";
                                                    obj.style.display = "";

                                                    //adjusts the position of style window
                                                    if (xOffset + obj.offsetWidth > windowWidth) {
                                                        obj.style.left = left - obj.offsetWidth + "px";
                                                    }

                                                    if (yOffset + obj.offsetHeight > windowHeight) {
                                                        obj.style.top = top - obj.offsetHeight + "px";
                                                    }
                                                }

                                                function editHeadStyle(e) {
                                                    editStyle(e, "headerContentStyle");
                                                }

                                                function editBodyStyle(e) {
                                                    editStyle(e, "bodyContentStyle");
                                                }

                                                function editBrokerLinkStyle(e) {
                                                    editStyle(e, "brokerLinkStyle");
                                                }

                                                function compareColor() {
                                                    var backgroundColorField = document.getElementById("backgroundColor");
                                                    var titleColorField = document.getElementById("title_font_color");
                                                    var descriptionColorField = document.getElementById("description_font_color");
                                                    var brokerColorField = document.getElementById("broker_link_font_color");
                                                    var colorReg = /^#[0-9a-fA-F]{6}$/;
                                                    if ('TRANSPARENT' != backgroundColorField.value && ! colorReg.test(backgroundColorField.value)) {
                                                        alert(alert_color_incorrect.replace('<field name>', backgroundColorField.nextSibling.firstChild.nodeValue));
                                                        focusElement(backgroundColorField);
                                                        return;
                                                    }
                                                    if (! colorReg.test(titleColorField.value)) {
                                                        alert(alert_color_incorrect.replace('<field name>', titleColorField.nextSibling.firstChild.nodeValue));
                                                        focusElement(titleColorField);
                                                        return;
                                                    }
                                                    if (! colorReg.test(descriptionColorField.value)) {
                                                        alert(alert_color_incorrect.replace('<field name>', descriptionColorField.nextSibling.firstChild.nodeValue));
                                                        focusElement(descriptionColorField);
                                                        return;
                                                    }
                                                    if (! colorReg.test(brokerColorField.value)) {
                                                        alert(alert_color_incorrect.replace('<field name>', brokerColorField.nextSibling.firstChild.nodeValue));
                                                        focusElement(brokerColorField);
                                                        return;
                                                    }
                                                    var titleColor = titleColorField ? titleColorField.value : previewer.style.head.lastFontColor;

                                                    if (!colorReg.test(titleColor) ||
                                                        (!colorReg.test(backgroundColorField.value) && ('TRANSPARENT' != backgroundColorField.value))) {
                                                        return false;
                                                    }

                                                    if (backgroundColorField.value.toUpperCase() == titleColor.toUpperCase()) {
                                                        alert("Background color and font colors cannot be the same.");
                                                        backgroundColorField.value = previewer.style.lastBackgroundColor;
                                                        titleColorField.value = previewer.style.head.lastFontColor;
                                                        return false;
                                                    }

                                                    return true;
                                                }

                                                function previewT() {
                                                    if (!compareColor()) return;
                                                    previewer.style.lastBackgroundColor = document.getElementById('backgroundColor').value;
                                                    previewer.style.head.lastFontColor = document.getElementById('title_font_color').value;
                                                    previewer.setBackgroundColor(document.getElementById("backgroundColor").value);
                                                    previewer.setStyle('head', 'color', document.getElementById("title_font_color").value);
                                                    previewer.setStyle('body', 'color', document.getElementById("description_font_color").value);
                                                    previewer.setStyle('brokerLink', 'color', document.getElementById("broker_link_font_color").value);
                                                }

                                                //previewT();
                                                break;
                                            default:
                                                break;
                                        }                                     
                                    }
                                }

                                function GetXmlHttpObject()
                                {
                                    if (window.XMLHttpRequest)
                                    {
                                        // code for IE7+, Firefox, Chrome, Opera, Safari
                                        return new XMLHttpRequest();
                                    }
                                    if (window.ActiveXObject)
                                    {
                                        // code for IE6, IE5
                                        return new ActiveXObject("Microsoft.XMLHTTP");
                                    }
                                    return null;
                                }
                                </script>
                                <select id="adspaceName" name="adspace_name" onchange="changeForm(this);" class="admob-CustomizeSmallDropDown">
                                <?php
//                                $sqlName = "select m.adspaceid, m.adspacename, d.adspacetype from adspace_master m
//                                            inner join (select adSpaceId, adspaceType from adspace_details) d
//                                            on m.adspaceid = d.adspaceid where userid='".$_SESSION['siteuserId']."' and m.adsiteid='".$_REQUEST['sid']."'
//                                            order by m.readydate desc";
//                                $recName = mysql_query($sqlName);
//                                while($row_adname=mysql_fetch_array($recName))
//                                {
                                ?>
                                    <option value="<?php //echo $row_adname['adspaceid']; ?>"><?php //echo $row_adname['adspacename']; ?></option>
                                <?php 
                                //}
                                ?>
                                </select>
                                <script type="text/javascript">
                                var sObj = document.getElementById('adspaceName');
                                changeForm(sObj);
                                </script>
                                <script type="text/javascript">
                                
                                </script>
                                <!--FOR TEXTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT-->
                                    <!--<script language="javascript" type="text/javascript">
                                    var confirm_hide_link = "Are you sure? If you hide the link, people will not be able to advertise on your site or become your affiliate.";
                                    var descriptionString = "Ad description will go here below the Headline.";
                                    var titleString = "Headline Goes Here";
                                    var descString = "Ad description will go here.";
                                    </script>
                                    <script language="javascript" type="text/javascript">
                                    function showWarning(isOverflow) {
                                        warning.style.display = isOverflow ? 'block' : 'none';
                                    }

                                    function hideBrokerLink(){
                                        if ("Yes" == document.getElementById("brokerLinkHide").value) {
                                            if (!window.confirm(confirm_hide_link)) {
                                            document.getElementById("brokerLinkHide").value = "No";
                                            }
                                        }
                                    }
                                    function restoreDefault() {
                                        if (!document.all && onchangeFlag) {
                                            return;
                                        }
                                        if (null != document.getElementById("siteId")) {
                                            document.getElementById("siteId").options[0].selected = true;
                                            changeRating();
                                        }
                                    document.getElementById("size").options[0].selected = true;
                                    document.getElementById("vertical").checked = true;
                                    document.getElementById("cellCount").options[0].selected = true;
                                    document.getElementById("backgroundColor").value = "#E8E8E8";
                                    document.getElementById("titleColor").value = "#0000FF";
                                    document.getElementById("descriptionColor").value = "#000000";
                                    document.getElementById("fontType").value = "Arial";
                                    document.getElementById("brokerLinkHide").options[0].selected = true;
                                    preview();
                                    }

                                    function restoreDefaultSize() {
                                    document.getElementById("cellCount").options[0].selected = true;
                                    document.getElementById("vertical").checked = true;
                                    preview();
                                    }

                                    function preview() {
                                    var elementTitleColor = document.getElementById("titleColor");
                                    var elementDescriptionColor = document.getElementById("descriptionColor");
                                    var elementBgColor = document.getElementById("backgroundColor");
                                    var reg = /^#[0-9a-fA-F]{6}$/;
                                    if ('TRANSPARENT' != elementBgColor.value && ! reg.test(elementBgColor.value)) {
                                    alert(alert_color_incorrect.replace('<field name>', elementBgColor.nextSibling.firstChild.nodeValue));
                                    focusElement(elementBgColor);
                                    return;
                                    }
                                    if (! reg.test(elementTitleColor.value)) {
                                    alert(alert_color_incorrect.replace('<field name>', elementTitleColor.nextSibling.firstChild.nodeValue));
                                    focusElement(elementTitleColor);
                                    return;
                                    }
                                    if (! reg.test(elementDescriptionColor.value)) {
                                    alert(alert_color_incorrect.replace('<field name>', elementDescriptionColor.nextSibling.firstChild.nodeValue));
                                    focusElement(elementDescriptionColor);
                                    return;
                                    }
                                    var fontName = document.getElementById("fontType").value;
                                    var titleColor = document.getElementById("titleColor").value;
                                    var descriptionColor = document.getElementById("descriptionColor").value;
                                    var bgColor = document.getElementById("backgroundColor").value;
                                    var size = document.getElementById("size").value;
                                    document.getElementById("horizontal").disabled = true;
                                    document.getElementById("vertical").disabled = true;
                                    document.getElementById("cellCount").disabled = true;
                                    var alignment = "vertical";
                                    var titleFontSize = "13px";
                                    var descriptionFontSize = "13px";
                                    var titleText = titleString;
                                    var descriptionText = descriptionString;
                                    cellSpacing = 6;
                                    cellPadding = 6;
                                    rows = 1;
                                    cols = 1;
                                    sizes = size.split("x");
                                    totalWidth = sizes[0];
                                    totalHeight = sizes[1];

                                    switch (size) {
                                    case "184x360" :
                                    ads = 5;
                                    rows = 5;
                                    descriptionFontSize = "12px";
                                    break;
                                    case "468x60" :
                                    ads = 2;
                                    cellSpacing = 6;
                                    alignment = "horizontal";
                                    cols = 2;
                                    titleFontSize = "12px";
                                    descriptionFontSize = "11px";
                                    break;
                                    case "234x60" :
                                    ads = 1;
                                    cellSpacing = 6;
                                    titleFontSize = "12px";
                                    descriptionFontSize = "12px";
                                    break;
                                    case "728x90" :
                                    ads = 5;
                                    alignment = "horizontal";
                                    cols = 5;
                                    descriptionFontSize = "12px";
                                    descriptionText = descString;
                                    break;
                                    case "125x125" :
                                    ads = 1;
                                    cellSpacing = 0;
                                    titleFontSize = "12px";
                                    descriptionFontSize = "12px";
                                    break;
                                    case "120x240" :
                                    ads = 3;
                                    rows = 3;
                                    titleFontSize = "12px";
                                    descriptionFontSize = "12px";
                                    descriptionText = descString;
                                    break;
                                    case "180x150" :
                                    ads = 1;
                                    titleFontSize = "12px";
                                    descriptionFontSize = "12px";
                                    break;
                                    case "300x250" :
                                    ads = 4;
                                    cols = 2;
                                    rows = 2;
                                    break;
                                    case "336x280" :
                                    ads = 6;
                                    cols = 3;
                                    rows = 2;
                                    break;
                                    case "250x250" :
                                    ads = 4;
                                    cols = 2;
                                    rows = 2;
                                    break;
                                    case "120x600" :
                                    ads = 6;
                                    rows = 6;
                                    break;
                                    case "160x600" :
                                    ads = 7;
                                    rows = 7;
                                    break;
                                    default :
                                    document.getElementById("horizontal").disabled = false;
                                    document.getElementById("vertical").disabled = false;
                                    document.getElementById("cellCount").disabled = false;
                                    ads = document.getElementById("cellCount").value;
                                    cellSpacing = 6;
                                    if (document.getElementById("horizontal").checked) {
                                    alignment = "horizontal";
                                    cols = parseInt(ads);
                                    }
                                    else {
                                    rows = parseInt(ads);
                                    }
                                    width = sizes[0];
                                    height = sizes[1];
                                    totalWidth = width*cols;
                                    totalHeight = height*rows;
                                    break;
                                    }

                                    //if ("vertical" == alignment) {
                                    //document.getElementById("vertical").checked = true;
                                    //}
                                    //else {
                                    //document.getElementById("horizontal").checked = true;
                                    //}

                                    if ("No" == document.getElementById("brokerLinkHide").value) {
                                    totalHeight -= 21;
                                    }
                                    temp = cellPadding * (rows * 2) + cellSpacing * (rows + 1);
                                    height = Math.round((totalHeight - temp)/rows);
                                    temp = cellPadding * (cols * 2) + cellSpacing * (cols + 1);
                                    width = Math.round((totalWidth - temp)/cols);

                                    document.getElementById("cellCount").value = ads;
                                    document.getElementById("pTd").innerHTML = "";
                                    previewTable = document.createElement("TABLE");
                                    previewTableBody = document.createElement("TBODY");
                                    var index = 0;
                                    var ad_elements = new Array();
                                    for(j = 0; j < rows; j++) {
                                    currentRow = document.createElement("TR");
                                    for(i = 0; i < cols;i++) {
                                    currentCell = document.createElement("TD");
                                    if ("" != bgColor) {
                                    currentCell.bgColor = bgColor;
                                    }
                                    currentCell.vAlign = "top";
                                    currentCell.align = "center";
                                    content = document.createElement("DIV");
                                    content.id = "ad_" + index;
                                    ad_elements[index++] = content;
                                    content.style.overflow = "hidden";
                                    content.style.width = width + "px";
                                    content.style.height = height + "px";
                                    title = document.createElement("DIV");
                                    title.style.color = titleColor;
                                    title.style.fontFamily = fontName;
                                    title.style.fontSize = titleFontSize;
                                    title.style.fontWeight = "bold";
                                    title.style.textDecoration = "underline";
                                    titleContent = document.createTextNode(titleString);
                                    title.appendChild(titleContent);
                                    description = document.createElement("DIV");
                                    description.style.color = descriptionColor;
                                    description.style.fontFamily = fontName;
                                    description.style.fontSize = descriptionFontSize;
                                    descriptionContent = document.createTextNode(descriptionText);
                                    description.appendChild(descriptionContent);
                                    content.appendChild(title);
                                    content.appendChild(description);
                                    currentCell.appendChild(content);
                                    currentRow.appendChild(currentCell);
                                    }
                                    previewTableBody.appendChild(currentRow);
                                    }

                                    var brokerLinkElement = document.getElementById("brokerLink");
                                    if ("No" == document.getElementById("brokerLinkHide").value) {
                                    brokerLinkElement.style.display = "inline";
                                    }
                                    else {
                                    brokerLinkElement.style.display = "none";
                                    }
                                    previewTable.brokerLinkSpan = document.getElementById('brokerLinkSpan');
                                    previewTable.totalWidth = totalWidth;
                                    previewTable.appendChild(previewTableBody);
                                    previewTable.setAttribute("border", "0");
                                    previewTable.cellSpacing = cellSpacing;
                                    previewTable.cellPadding = cellPadding;
                                    previewTable.style.width = totalWidth + "px";
                                    previewTable.style.height = totalHeight + "px";
                                    previewTable.style.tableLayout = "fixed";
                                    document.getElementById("pTd").appendChild(previewTable);
                                    var striped = stripAllContents(ad_elements);
                                    if ("No" == document.getElementById("brokerLinkHide").value) {
                                    striped |= stripBrokerLink(previewTable);
                                    }
                                    if (isIE7()) {
                                    controlIE7Performance();
                                    }
                                    showWarning(striped);
                                    if ('undefined' != typeof(isChanged)){
                                    isChanged = true;
                                    }
                                    }

                                    var oldOnload = window.onload;
                                    window.onload = function() {
                                    if (oldOnload) {
                                    oldOnload();
                                    }
                                    warning = document.createElement('div');
                                    warning.style.display = 'none';
                                    var previewTable = document.getElementById("pTable");
                                    //previewTable.parentNode.insertBefore(warning, previewTable);
                                    preview();
                                    if ('undefined' != typeof(isChanged)){
                                    isChanged = false;
                                    addLinksCheckChange(leave_message);
                                    }
                                    }
                                    </script>
                                    <script language="javascrip" type="text/javascript">
                                    var websites_rating = new Array();
                                        websites_rating['72687'] = 'nsfw';
                                        websites_rating['72719'] = 'nsfw';
                                    var ratings = {'sfw' : 'Safe For Work', 'nsfw' : 'Not Safe For Work', 'adult' : 'Adult'};

                                    function storeLayout() {
                                        document.getElementById('customAdSpace').disabled = false;
                                        document.getElementById('basicLayout').submit();
                                        return false;
                                    }
                                    </script>

                                    <!--FOR BANNERRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR-->
                                    <!--<script language="javascript" type="text/javascript">
                                    <!--

                                    var confirm_hide_link = "Are you sure? If you hide the link, people will not be able to advertise on your site or become your affiliate.";
                                    var alert_choose_website = "Please choose a website from the dropdown list";
                                    var alert_same_header_color_and_background_color = "The background color and header color should not be the same.";
                                    var alert_same_body_color_and_background_color = "The background color and body color should not be the same.";
                                    var leave_message = "Do you want to save your changes?";
                                    var image_path = "images/";
                                    //var location_url = 'selling-adspace-list.php?sid=2d47b082c2e464ec257bb48468c0ddfb';
                                    var old_size = "120x240";
                                    var old_broker_hide = "No";
                                    var confirm_edit_dimension_change = "The dimensions of this Ad Space have changed. If you are using Iframe Mode Ad Space Code, you will need to copy the new code and include it on your website in order for the dimensions appear correctly.";
                                    var is_edit = false;

                                    var changed = false;

                                    function setTemplateAppearance(configAppearance) {
                                        if (configAppearance) {
                                            var configAppearanceTable = document.getElementById('configAppearanceTable');
                                            configAppearanceTable.style.display = 'block';
                                            var inputs = configAppearanceTable.getElementsByTagName('input');
                                            for (var i = 0; i < inputs.length; i++) {
                                                if ('text' == inputs[i].type) {
                                                    nextSibling = inputs[i].nextSibling;
                                                    if ((nextSibling != null) && (nextSibling.nodeType == 1) && (nextSibling.tagName == "A")){
                                                        nextSibling.className = 'colorformat';
                                                    }
                                                }
                                            }
                                        }
                                        else {
                                            var configAppearanceTable = document.getElementById('configAppearanceTable');
                                            configAppearanceTable.style.display = 'none';
                                            var inputs = configAppearanceTable.getElementsByTagName('input');
                                            for (var i = 0; i < inputs.length; i++) {
                                                if ('text' == inputs[i].type) {
                                                    nextSibling = inputs[i].nextSibling;
                                                    if ((nextSibling != null) && (nextSibling.nodeType == 1) && (nextSibling.tagName == "A")){
                                                        nextSibling.className = '';
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    function changeStyle(type, srcElement, destElementName) {
                                        if ('color' == type) {
                                            var color = srcElement.value;
                                            if ('backgroundColor' == srcElement.id) {
                                                document.getElementById('previewBackgroundColor').style.backgroundColor = color;
                                                document.getElementById('previewHeaderStyle').style.backgroundColor = color;
                                                document.getElementById('previewBodyStyle').style.backgroundColor = color;
                                            }
                                            else {
                                                document.getElementById(destElementName).style.color = color;
                                            }
                                        }
                                        else if ('fontType' == type) {
                                            var fontType = srcElement.value;
                                            document.getElementById(destElementName).style.fontFamily = fontType;
                                        }
                                    }

                                    function processBack() {
                                        if (checkChange(changed, leave_message)) {
                                            window.location.href = location_url;
                                        }
                                    }


                                    function previewB() {
                                        var image = document.getElementById("bannerImage");
                                        var sizeObject = document.getElementById("sizeB");

                                        var size = document.getElementById("sizeB").value;
                                        var sizes = size.split("x");
                                        var width = sizes[0];
                                        var height = sizes[1];

                                        image.style.width = width + "px";
                                        image.style.height = height+ "px";
                                        image.src = image_path + "ad_test_" + size + ".jpg";

                                        if (isIE7()) {
                                            controlIE7Performance();
                                        }

                                    }

                                    function validate() {
                                        var result = true;
                                        var objSite = document.getElementById("siteId");
                                        var result2 = true;
                                        if (null != objSite) {
                                            if ("0" == objSite.value) {
                                                alert(alert_choose_website);
                                                objSite.focus();
                                                return false;
                                            }
                                        }
                                        result = validateForm(document.getElementById("bannerAdSpace"));
                                        if (result == false) {
                                            return false;
                                        }
                                        if (result && document.getElementById('config_appearance').checked) {
                                            bgColor = document.getElementById('backgroundColor').value;
                                            headerColor = document.getElementById('headerColor').value;
                                            bodyColor = document.getElementById('bodyColor').value;
                                            if (bgColor == headerColor) {
                                                alert(alert_same_header_color_and_background_color);
                                                document.getElementById('headerColor').focus();
                                                result = false;
                                            }
                                            else if (bgColor == bodyColor) {
                                                alert(alert_same_body_color_and_background_color);
                                                document.getElementById('bodyColor').focus();
                                                result = false;
                                            }
                                        }

                                        return result && result2;
                                    }
                                    previewB();

                                    var oldOnload = window.onload;
                                    window.onload = function() {
                                        if (oldOnload) {
                                            oldOnload();
                                        }
                                        if (isIE7()) {
                                            controlIE7Performance();
                                        }
                                        if (document.getElementById('config_appearance').checked) {
                                            setTemplateAppearance(true);
                                        }
                                    }

                                    -->
                                    <!--</script>

                                    <!--FOR THUMBNAILLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL-->
                                    <!--<script type="text/javascript" language="javascript" src="js.html"></script>
                                    <script type="text/javascript" language="javascript" src="JavaScripts/form.js"></script>
                <script type="text/javascript">
                if (null == window.GTBPreviewer) {
                }
                // -- Constructor --
                /**
                 * constructor of class GTBPreviewer which is used to preview GTB ads.
                 * @param object in_ads the GTB ads to be previewed
                 */
                var GTBPreviewer = function(inAds){
                    this.initialize(inAds);
                    this.adBlock = null;
                    this.adBox = null; //the table containing the ads
                    this.adCells = new Array(); //the cells DOM Node of the ad
                    this.adTitle = null; //the title DOM Node
                    this.adBrokerLink = null; //the broker link DOM Node
                    this.adBoxBody = this.headCell = this.footCell = null; //adBox components
                    this.index = ++GTBPreviewer.index; //The unique ID in the page
                };

                // -- API --
                //Overwrites this function to receive size change event. The function will be invoked
                //and get the new width and height when the size has been changed.
                GTBPreviewer.prototype.onSizeChange = function(width, height){return;};

                // Sets On Click Handler
                GTBPreviewer.prototype.setHeadOnClickHandler = function(handler){
                    this.adBox.tHead.onclick = this.headHandler = handler;
                }
                GTBPreviewer.prototype.setBodyOnClickHandler = function(handler){
                    this.adBoxBody.onclick = this.bodyHandler = handler;
                }
                GTBPreviewer.prototype.setBrokerLinkOnClickHandler = function(handler){
                    this.adBox.tFoot.onclick = this.brokerLinkHandler = handler;
                }

                //Initializes the previewer
                GTBPreviewer.prototype.initialize = function(inAds) {
                    this.spacer = inAds.spacer;
                    this.location = inAds.location;
                    this.title = inAds.payment.title;
                    this.themeId = inAds.space.themeId;
                    this.rating = inAds.space.rating;
                    var style = inAds.space.style;
                    this.size = null;
                    if ((null != style.width) && (null != style.height)) {
                        this.size = {
                            width: style.width,
                            height: style.height
                        };
                    }
                    this.view = (GTBPreviewer.VERTICAL == style.view) ? GTBPreviewer.VERTICAL : GTBPreviewer.HORIZONTAL;
                    this.cells = style.cells;
                    this.imageSize = {
                        width: style.imageWidth,
                        height:style.imageHeight
                    };
                    this.components = {
                        handle: style.showHandle,
                        age: style.showAge,
                        city: style.showLocation,
                        headline: style.showHeadline,
                        brokerLink: style.showBrokerLink,
                        image: style.showImage,
                        header: style.showHeader
                    };
                    this.style = {
                        background: style.backgroundColor,
                        head: GTBPreviewer.styleStringToObject(style.headStyle),
                        body: GTBPreviewer.styleStringToObject(style.bodyStyle),
                        brokerLink: GTBPreviewer.styleStringToObject(style.brokerLinkStyle)
                    };
                    this.requestURL = inAds.requestURL;
                    this.baseURL = inAds.baseURL;
                };

                //Sets the size of the ads. Sets to auto if there's no argument.
                GTBPreviewer.prototype.setSize = function(width, height){
                    if (0 == arguments.length) {
                        this.size = null;
                    }
                    else {
                        width = parseInt(width);
                        height = parseInt(height);
                        if (isNaN(width) || isNaN(height)) {
                            return;
                        }
                        this.size = {
                            width: width,
                            height: height
                        };
                    }
                    this.updateSize();
                };

                //Sets orientation.
                GTBPreviewer.HORIZONTAL = 'horizontal';
                GTBPreviewer.VERTICAL = 'vertical';
                GTBPreviewer.prototype.setView = function(view){
                    if (1 > this.cells) {
                        return;
                    }
                    var resize = false;
                    if ((GTBPreviewer.HORIZONTAL == view) && (GTBPreviewer.VERTICAL == this.view)) { //v to h
                        this.headCell.colSpan = this.cells;
                        this.footCell.colSpan = this.cells;
                        var rows = this.adBoxBody.rows;
                        var rowsLength = rows.length;
                        for (var i = 1; i < rowsLength; ++i) {
                            rows[0].appendChild(rows[i].cells[0]);
                        }
                        for (var i = rowsLength - 1; 1 <= i; --i) {
                            this.adBoxBody.deleteRow(i);
                        }
                        this.view = view;
                        resize = true;
                    }
                    else if ((GTBPreviewer.VERTICAL == view) && (GTBPreviewer.HORIZONTAL == this.view)) { //h to v
                        this.headCell.colSpan = 1;
                        this.footCell.colSpan = 1;
                        var cells = this.adBoxBody.rows[0].cells;
                        var cellsLength = cells.length;
                        for (var i = cellsLength - 1; 1 <= i; --i) {
                            this.adBoxBody.insertRow(1).appendChild(cells[i]);
                        }
                        this.view = view;
                        resize = true;
                    }
                    if (resize) {
                        this.updateSize();
                    }
                };

                //Sets Cells Count.
                GTBPreviewer.prototype.setCount = function(count) {
                    count = parseInt(count);
                    if (isNaN(count) || (count == this.cells)) {
                        return;
                    }
                    var resize = false;
                    var isVertical = (this.view == GTBPreviewer.VERTICAL);
                    if (count < this.cells) {
                        if (isVertical) {
                            for (var i = this.cells - 1; count <= i; --i) {
                                this.adCells[i] = this.adCells[i].parentNode.removeChild(this.adCells[i]);
                                this.adBoxBody.deleteRow(i);
                            }
                        }
                        else {
                            for (var i = this.cells - 1; count <= i; --i) {
                                this.adCells[i] = this.adCells[i].parentNode.removeChild(this.adCells[i]);
                                this.adBoxBody.rows[0].deleteCell(i);
                            }
                        }
                        this.cells = count;
                        this.headCell.colSpan = this.footCell.colSpan = isVertical ? 1 : count;
                        resize = true;
                    }
                    else if (count <= this.adCells.length) {
                        if (isVertical) {
                            for (var i = this.cells; i < count; ++i) {
                                this.adBoxBody.insertRow(i).insertCell(0).appendChild(this.adCells[i]);
                            }
                        }
                        else {
                            for (var i = this.cells; i < count; ++i) {
                                this.adBoxBody.rows[0].insertCell(i).appendChild(this.adCells[i]);
                            }
                        }
                        this.cells = count;
                        this.headCell.colSpan = this.footCell.colSpan = isVertical ? 1 : count;
                        this.clipTable(this.adBox);
                        resize = true;
                    }
                    else {
                        for (var i = this.cells; i < count; ++i) {
                            if (i >= this.adCells.length) {
                                this.adCells[i] = this.createCell();
                            }
                            if (GTBPreviewer.VERTICAL != this.view) {
                                this.adBoxBody.rows[0].insertCell(i).appendChild(this.adCells[i]);
                            }
                            else {
                                this.adBoxBody.insertRow(i).insertCell(0).appendChild(this.adCells[i]);
                            }
                        }
                        this.headCell.colSpan = this.footCell.colSpan = isVertical ? 1 : count;
                        this.clipTable(this.adBox);
                        this.cells = count;
                        this.renderEntries();
                    }
                    if (resize) {
                        this.updateSize();
                    }
                };

                //Sets Component. Shows it or hiddens.
                GTBPreviewer.prototype.setComponent = function(componentName, isShow){
                    if ('location' == componentName) {
                        componentName = 'city';
                    }
                    if ('brokerlink' == componentName) {
                        componentName = 'brokerLink';
                    }
                    if(componentName in this.components) {
                        this.components[componentName] = isShow;
                    }
                    for (var i = 0; i < this.adCells.length; ++i) {
                        for (var name in this.components) {
                            if (('brokerLink' != name) && ('header' != name)) {
                                this.adCells[i][name].style.display = this.components[name] ? 'block' : 'none';
                            }
                        }
                    }
                    this.adBrokerLink.parentNode.style.display = this.components.brokerLink ? '' : 'none';
                    this.adTitle.parentNode.style.display = this.components.header ? '' : 'none';
                    this.updateSize();
                };

                //Sets Image Size
                GTBPreviewer.prototype.setImageSize = function(width, height){
                    width = parseInt(width) > 0 ? parseInt(width) : 1;
                    height = parseInt(height) > 0 ? parseInt(height) : 1;
                    if ((this.imageSize.width != width) || (this.imageSize.height != height)) {
                        this.imageSize = {
                            width: width,
                            height:height
                        };
                        for (var i = 0; i < this.adCells.length; ++i) {
                            var gtbImage = this.adCells[i].image.getElementsByTagName('img')[0];
                            var newSrc = gtbImage.src;
                            newSrc = newSrc.substring(0, newSrc.indexOf('?'));
                            newSrc += this.baseURL;
                            newSrc += '&id=' + this.adCells[i].imageId;
                            newSrc += '&width=' + this.imageSize.width;
                            newSrc += '&height=' + this.imageSize.height;
                            gtbImage.src = newSrc;
                            gtbImage.style.width = this.imageSize.width + 'px';
                            gtbImage.style.height = this.imageSize.height + 'px';
                        }
                        this.updateSize();
                    }
                };

                //Sets Title.
                GTBPreviewer.prototype.setTitle = function(title){
                    this.title = title;
                    var city = (0 < this.location.nearbyCities.length) ?
                            this.location.nearbyCities[Math.floor(Math.random() * this.location.nearbyCities.length)] :
                            this.location.cityName;
                    this.adTitle.firstChild.data = this.adTitle.bak = title.replace(/\{city\}/ig, this.location.cityName).replace(/\{cities\}/ig, city);
                    this.updateSize();
                };

                //Sets Theme
                GTBPreviewer.prototype.setTheme = function(themeId){
                    if (this.themeId != themeId) {
                        this.themeId = themeId;
                        this.refresh();
                    }
                };

                //Sets Background
                GTBPreviewer.prototype.setBackgroundColor = function(color){
                    this.style.background = color;
                    this.clipTable(this.adBox);
                };

                //Sets the style of each part
                //Part Constant
                GTBPreviewer.HEAD = 'head';
                GTBPreviewer.BODY = 'body';
                GTBPreviewer.BROKER_LINK = 'brokerLink';
                //Sets the attribute named 'name' of the 'part' to 'value'
                GTBPreviewer.prototype.setStyle = function(part, name, value){
                    if (part in this.style) {
                        this.style[part][name] = value;
                    }
                    switch (part) {
                        case GTBPreviewer.HEAD: {
                            for (var styleName in this.style.head) {
                                this.adTitle.style[styleName] = this.style.head[styleName];
                            }
                        }
                        break;
                        case GTBPreviewer.BODY: {
                            for (var styleName in this.style.body) {
                                for (var i = 0; i < this.adCells.length; ++i) {
                                    this.adCells[i].textBlock.style[styleName] = this.style.body[styleName];
                                }
                            }
                        }
                        break;
                        case GTBPreviewer.BROKER_LINK: {
                            for (var styleName in this.style.brokerLink) {
                                this.adBrokerLink.style[styleName] = this.style.brokerLink[styleName];
                                this.adBrokerLink.firstChild.style[styleName] = this.style.brokerLink[styleName];
                            }
                        }
                        break;
                        default:
                        break;
                    }
                    this.updateSize();
                };
                // END OF API //

                // -- Class Data Member --
                //The unique index for every GTB previewer in one page
                GTBPreviewer.index = 0;

                //Space Constant
                GTBPreviewer.CELL_PADDING = 3; // Padding of the table cell
                GTBPreviewer.LINE_SPACING = 3; // Spacing between each line
                GTBPreviewer.BODY_PADDING = 5; // Space between title and body, body and broker link.
                GTBPreviewer.LENTH_ADJUST = 2 * GTBPreviewer.CELL_PADDING;

                // -- Class Method --
                //Translates the style string to object
                GTBPreviewer.styleStringToObject = function(styleString){
                    objStyle = new Object();
                    if ((null != styleString) && 0 < (styleString.length)) {
                        var stylePairs = styleString.split(';');
                        var indexOfPair = 0;
                        var name = '';
                        var value = '';
                        for (var i = 0; i < stylePairs.length; ++i) {
                            indexOfPair = stylePairs[i].indexOf(':');
                            if (0 < indexOfPair) {
                                name = stylePairs[i].substr(0, indexOfPair);
                                value = stylePairs[i].substr(indexOfPair + 1);
                                objStyle[name] = value;
                            }
                        }
                    }

                    return objStyle;
                };

                //Translates the style object to style
                GTBPreviewer.styleObjectToString = function(styleObject){
                    strStyle = '';
                    if (null != styleObject) {
                        for (var styleName in styleObject) {
                            if ('' != strStyle) {
                                strStyle += ';';
                            }
                            strStyle += styleName + ':' + styleObject[styleName];
                        }
                    }

                    return strStyle;
                };

                // -- Instance Method --
                //renders the GTB
                GTBPreviewer.prototype.render = function(){
                    this.adTitle = this.createTitle();
                    this.adCells = this.createCells();
                    this.adBrokerLink = this.createBrokerLink();

                    this.adBox = this.createAdBox(this.adTitle, this.adCells, this.adBrokerLink);
                    var gtbAdBlockId = 'gtb_ad_block_' + this.index;
                    var ab = document.getElementById('adPreBox');
                    ab.innerHTML = '<div id="' + gtbAdBlockId + '"></div>';
                    //document.write('<div id="' + gtbAdBlockId + '"></div>');
                    this.adBlock = document.getElementById(gtbAdBlockId);
                    this.adBlock.style.border = 'none';
                    this.adBlock.style.margin = this.adBlock.style.padding = '0px';
                    this.adBlock.previewer = this;
                    this.adBlock.appendChild(this.adBox);
                    this.adBlock.style.overflow = 'hidden';
                    this.renderEntries();
                };

                GTBPreviewer.prototype.refresh = function(){
                    this.adBlock.removeChild(this.adBox);

                    this.adTitle = this.createTitle();
                    this.adCells = this.createCells();
                    this.adBrokerLink = this.createBrokerLink();
                    this.adBox = this.createAdBox(this.adTitle, this.adCells, this.adBrokerLink);
                    this.adBlock.appendChild(this.adBox);
                    this.adBlock.style.overflow = 'hidden';
                    if (this.headHandler) {
                        this.setHeadOnClickHandler(this.headHandler);
                    }
                    if (this.bodyHandler) {
                        this.setBodyOnClickHandler(this.bodyHandler);
                    }
                    if (this.brokerLinkHandler) {
                        this.setBrokerLinkOnClickHandler(this.brokerLinkHandler);
                    }
                    this.renderEntries();
                };

                //Gets the entries by AJAX
                GTBPreviewer.prototype.renderEntries = function() {
                    var data = 'theme_id=' + escape(this.themeId) +
                        '&rating=' + escape(this.rating) +
                        '&cells=' + escape(this.cells) +
                        '&city=' + escape(this.location.cityName);
                    if (('latitude' in this.location) && ('longitude' in this.location)) {
                        data += '&latitude=' + escape(this.location.latitude) +
                                '&longitude=' + escape(this.location.longitude);
                    }
                    if ('' != this.requestURL) {
                        new AjaxRequest(this.requestURL + this.baseURL, data, this);
                    }
                }

                //Creates each part respectively
                GTBPreviewer.prototype.createTitle = function(){
                    var adTitle = createDiv();
                    adTitle.style.paddingBottom = GTBPreviewer.BODY_PADDING + 'px';
                    adTitle.previewer = this; //reference to the previewer
                    for (var styleName in this.style.head) {
                        adTitle.style[styleName] = this.style.head[styleName];
                    }
                    var city = (0 < this.location.nearbyCities.length) ?
                        this.location.nearbyCities[Math.floor(Math.random() * this.location.nearbyCities.length)] :
                        this.location.cityName;
                    adTitle.bak = this.title.replace(/\{city\}/ig, this.location.cityName).replace(/\{cities\}/ig, city);
                    adTitle.appendChild(document.createTextNode(adTitle.bak));

                    return adTitle;
                };
                GTBPreviewer.prototype.createCell = function() {
                    var adCell = createDiv();
                    var isShow = this.components;

                    adCell.image = createDiv();
                    adCell.image.innerHTML = '<img src="' + this.spacer + '" style="border:none;width:' + this.imageSize.width +
                            'px;height:' + this.imageSize.height + 'px" />';
                    adCell.imageId = 0;
                    adCell.image.style.textAlign = 'center';
                    adCell.image.style.display = isShow.image ? 'block' : 'none';
                    adCell.appendChild(adCell.image);

                    adCell.textBlock = createDiv();
                    adCell.handle = document.createElement('span');
                    adCell.age = document.createElement('span');
                    adCell.city = document.createElement('span');
                    adCell.headline = document.createElement('span');
                    adCell.handle.innerHTML = adCell.handle.bak = textHandle;
                    adCell.age.innerHTML = adCell.age.bak = textAgeEighteen;
                    adCell.city.innerHTML = adCell.city.bak = textLocation;
                    adCell.headline.innerHTML = adCell.headline.bak = textHeadline;
                    adCell.handle.style.display = isShow.handle ? 'block' : 'none';
                    adCell.textBlock.appendChild(adCell.handle);
                    adCell.age.style.display = isShow.age ? 'block' : 'none';
                    adCell.textBlock.appendChild(adCell.age);
                    adCell.city.style.display = isShow.city ? 'block' : 'none';
                    adCell.textBlock.appendChild(adCell.city);
                    adCell.headline.style.display = isShow.headline ? 'block' : 'none';
                    adCell.textBlock.appendChild(adCell.headline);
                    adCell.handle.style.padding = adCell.city.style.padding = GTBPreviewer.CELL_PADDING + 'px 0px';
                    adCell.age.style.padding = adCell.headline.style.padding = GTBPreviewer.CELL_PADDING + 'px 0px';
                    adCell.appendChild(adCell.textBlock);

                    adCell.previewer = this;
                    for (var styleName in this.style.body) {
                        adCell.textBlock.style[styleName] = this.style.body[styleName];
                    }

                    return adCell;
                }
                GTBPreviewer.prototype.createCells = function(){
                    adCells = new Array();
                    for (var i = 0; i < this.cells; ++i) {
                        adCells[i] = this.createCell();
                    }

                    return adCells;
                };
                GTBPreviewer.prototype.createBrokerLink = function(){
                    var brokerLink = createDiv();
                    brokerLink.style.paddingTop = GTBPreviewer.BODY_PADDING + 'px';
                    var spanElement = document.createElement('span');
                    for (var styleName in this.style.brokerLink) {
                        brokerLink.style[styleName] = this.style.brokerLink[styleName];
                        spanElement.style[styleName] = this.style.brokerLink[styleName];
                    }
                    brokerLink.previewer = this;
                    spanElement.bak = spanElement.innerHTML = advertiseHere;
                    spanElement.style.cursor = 'pointer';
                    brokerLink.appendChild(spanElement);

                    return brokerLink;
                };

                //Creates the Table
                GTBPreviewer.prototype.createAdBox = function(adTitle, adCells, adBrokerLink){
                    var adBox = document.createElement('table');
                    adBox.previewer = this; //reference to the previewer
                    if (GTBPreviewer.HORIZONTAL == this.view) {
                        var bodyRow = adBox.insertRow(0);
                        for (var i = 0; i < adCells.length; ++i) {
                            bodyRow.insertCell(i).appendChild(adCells[i]);
                        }
                    }
                    else {
                        for (var i = 0; i < adCells.length; ++i) {
                            adBox.insertRow(i).insertCell(0).appendChild(adCells[i]);
                        }
                    }
                    this.adBoxBody = adBox.tBodies[0];
                    this.headCell = adBox.createTHead().insertRow(0).insertCell(0);
                    this.headCell.appendChild(adTitle);
                    this.footCell = adBox.createTFoot().insertRow(0).insertCell(0);
                    this.footCell.appendChild(adBrokerLink);
                    adTitle.parentNode.style.display = this.components.header ? '' : 'none';
                    adBrokerLink.parentNode.style.display = this.components.brokerLink ? '' : 'none';
                    if (GTBPreviewer.HORIZONTAL == this.view) {
                        this.headCell.colSpan = this.cells;
                        this.footCell.colSpan = this.cells;
                    }
                    this.adBoxBody.previewer = adBox.tHead.previewer = adBox.tFoot.previewer = this;
                    this.clipTable(adBox);
                    return adBox;
                };

                //Clips the table to make them uniform
                GTBPreviewer.prototype.clipTable = function(tableElement){
                    tableElement.border = '0px';
                    tableElement.cellPadding = '0px';
                    tableElement.cellSpacing = '0px';
                    tableElement.style.border = 'none';
                    tableElement.style.padding = '0px';
                    tableElement.style.margin = '0px';
                    tableElement.tHead.style.cursor = 'pointer';
                    tableElement.tHead.style.backgroundColor = this.style.background;
                    tableElement.tBodies[0].style.cursor = 'pointer';
                    tableElement.tBodies[0].style.backgroundColor = this.style.background;
                    tableElement.tFoot.style.backgroundColor = 'transparent';
                    tableElement.tBodies[0].onmouseover = tableElement.tHead.onmouseover = function(){
                        window.status = this.previewer.adTitle.bak;
                        return true;
                    }
                    tableElement.tBodies[0].onmouseout = tableElement.tHead.onmouseout = function(){
                        window.status = '';
                    }

                    var rows = tableElement.rows;
                    for (var i = 0; i < rows.length; ++i) {
                        rows[i].style.backgroundColor = this.style.background;
                        var cells = rows[i].cells;
                        for (var j = 0; j < cells.length; ++j) {
                            cells[j].style.padding = GTBPreviewer.CELL_PADDING + 'px';
                            cells[j].style.margin = '0px';
                            cells[j].style.border = 'none';
                            cells[j].style.verticalAlign = 'middle';
                            cells[j].style.backgroundColor = this.style.background;
                        }
                    }
                    var footRow = tableElement.tFoot.rows[0];
                    footRow.style.backgroundColor = 'transparent';
                    footRow.cells[0].style.backgroundColor = 'transparent';
                };

                //updates the size of the ad block and table, and wraps the text.
                GTBPreviewer.prototype.updateSize = function(){
                    //re arrange the layout.
                    for (var i = 0; i < this.cells; ++i) {
                        this.adCells[i].parentNode.style.width = 'auto';
                    }
                    for (var i = 0; i < this.adBox.rows.length; ++i) {
                        this.adBox.rows[i].style.height = 'auto';
                    }
                    this.adBox.style.width = 'auto';
                    this.adBox.style.height = 'auto';
                    this.adTitle.firstChild.data = this.adTitle.bak;
                    this.adTitle.style.height = 'auto';
                    this.adTitle.style.overflow = 'visible';
                    for (var i = 0; i < this.adCells.length; ++i) {
                        this.adCells[i].handle.firstChild.data = this.adCells[i].handle.bak;
                        this.adCells[i].age.firstChild.data = this.adCells[i].age.bak;
                        this.adCells[i].city.firstChild.data = this.adCells[i].city.bak;
                        this.adCells[i].headline.firstChild.data = this.adCells[i].headline.bak;
                        this.adCells[i].style.height = 'auto';
                        this.adCells[i].style.overflow = 'visible';
                    }
                    var percent = Math.floor(100 / this.headCell.colSpan) + '%';
                    for (var i = 0; i < this.cells; ++i) {
                        this.adCells[i].parentNode.style.width = percent;
                    }

                    if (null != this.size) {
                        this.adBlock.style.width = this.adBox.style.width = this.size.width + 'px';
                        this.adBlock.style.height = this.adBox.style.height = this.size.height + 'px';
                    }
                    else {
                        this.adBlock.style.width = Math.min((2 * (this.imageSize.width + GTBPreviewer.LENTH_ADJUST) * this.headCell.colSpan), Math.round(1.2 * this.adBox.offsetWidth)) + 'px';
                        this.adBlock.style.height = Math.round(1.2 * this.adBox.offsetHeight) + 'px';
                    }

                    this.stripText();

                    if (null == this.size) {
                        if (this.onOverflow) {
                            this.onOverflow(false);
                        }
                        this.adBlock.style.width = this.adBox.offsetWidth + 'px';
                        this.adBlock.style.height = this.adBox.offsetHeight + 'px';
                        this.adBox.style.width = this.adBlock.style.width;
                        this.adBox.style.height = this.adBlock.style.height;
                    }
                    else {
                        var diff = this.adBox.offsetHeight - this.adBlock.offsetHeight;
                        if (diff > 0) {
                            this.stripTextToOneLine(this.adTitle, Math.max(1, this.adBlock.offsetWidth - GTBPreviewer.LENTH_ADJUST),
                                                    parseInt(this.adBlock.style.height) - (this.adBox.tBodies[0].offsetHeight + this.adBox.tFoot.offsetHeight));
                            this.adBox.tHead.rows[0].style.height = (this.adTitle.offsetHeight + GTBPreviewer.LENTH_ADJUST) + 'px';
                        }
                        diff = this.adBox.offsetHeight - this.adBlock.offsetHeight;
                        if (this.onOverflow) {
                            this.onOverflow((diff > 0) || (this.adBox.offsetWidth > this.adBlock.offsetWidth));
                        }
                        if (diff > 0) {
                            var cellDiff = diff;
                            if (GTBPreviewer.VERTICAL == this.view) {
                                cellDiff /= Math.max(1, this.cells);
                                cellDiff = Math.floor(cellDiff);
                            }
                            for (var i = 0; i < this.adCells.length; ++i) {
                                this.adCells[i].style.overflow = 'hidden';
                                this.adCells[i].style.height = Math.max(0, this.adCells[i].offsetHeight - cellDiff) + 'px';
                            }
                            diff = this.adBox.offsetHeight - this.adBlock.offsetHeight;
                            if (diff > 0) {
                                this.adTitle.style.overflow = 'hidden';
                                this.adTitle.style.height = Math.max(0, this.adTitle.offsetHeight - diff) + 'px';
                            }
                        }
                    }

                    if (null != this.onSizeChange) {
                        this.onSizeChange(this.adBlock.offsetWidth, this.adBlock.offsetHeight);
                    }

                    if (('function' == typeof isIE7) && isIE7()) {
                        controlIE7Performance();
                    }
                };
                GTBPreviewer.prototype.stripText = function(){
                    var adjust = GTBPreviewer.LENTH_ADJUST;
                    this.wrapText(this.adTitle, Math.max(1, this.adBlock.offsetWidth - adjust));
                    this.stripTextToOneLine(this.adBrokerLink.firstChild, Math.max(1, this.adBlock.offsetWidth - adjust));
                    var colWidth = Math.max(1, Math.floor(this.adBlock.offsetWidth / this.headCell.colSpan));
                    colWidth = Math.max(this.imageSize.width, colWidth - adjust);
                    for (var i = 0; i < this.cells; ++i) {
                        this.stripTextToOneLine(this.adCells[i].handle, colWidth);
                        this.stripTextToOneLine(this.adCells[i].age, colWidth);
                        this.stripTextToOneLine(this.adCells[i].city, colWidth);
                        this.stripTextToOneLine(this.adCells[i].headline, colWidth);
                    }
                    for (var name in this.components) {
                        if (this.components[name] && ('brokerLink' != name) && ('header' != name)) {
                            this.tidyHeight(name);
                        }
                    }
                    this.adBox.tHead.rows[0].style.height = (this.adTitle.offsetHeight + adjust) + 'px';
                    if (this.components.brokerLink) {
                        this.adBox.tFoot.rows[0].style.height = (this.adBrokerLink.offsetHeight + adjust) + 'px';
                    }

                    if (null != this.size) {
                        var diffHeight = this.adCells[0].parentNode.offsetHeight - this.adCells[0].offsetHeight - adjust;
                        var names = new Array();
                        for (var name in this.components) {
                            if (('brokerLink' != name) && ('header' != name) && this.components[name]) {
                                names[names.length] = name;
                            }
                        }
                        if ((0 < diffHeight) && (0 < names.length)) {
                            diffHeight /= (names.length * 2);
                            diffHeight = parseInt(diffHeight);
                            for (var i = 0; i < this.cells; ++i) {
                                for (var j = 0; j < names.length; ++j) {
                                    var component = this.adCells[i][names[j]];
                                    var paddingVertical = parseInt(component.style.paddingTop) + diffHeight;
                                    component.style.padding = paddingVertical + 'px 0px';
                                }
                            }
                        }
                    }
                };
                GTBPreviewer.prototype.wrapText = function(elementNode, width){
                    elementNode.style.width = '1px';
                    elementNode.firstChild.data = elementNode.bak;
                    elementNode.style.overflow = "hidden";

                    if (elementNode.scrollWidth > width) {
                        var allText = elementNode.bak;
                        elementNode.removeChild(elementNode.firstChild);
                        var lastPointer = pointer = 0;
                        var lineText = null;
                        var strippedText = '';
                        var lineNode = document.createTextNode('');
                        elementNode.appendChild(lineNode);
                        while (pointer < allText.length) {
                            lastPointer = pointer;
                            lineNode.data = lineText = '';
                            while ((elementNode.scrollWidth < width) && (pointer < allText.length)) {
                                lineText = lineNode.data;
                                lineNode.data += allText.charAt(pointer++);
                            }
                            if (elementNode.scrollWidth > width) {
                                --pointer;
                            }
                            else {
                                lineText = lineNode.data;
                            }
                            if (lastPointer == pointer) {
                                break;
                            }
                            strippedText += (lineText + ' ');
                        }
                        elementNode.replaceChild(document.createTextNode((null != strippedText) ? strippedText : allText), lineNode);
                    }
                    elementNode.style.overflow = 'visible';
                    elementNode.style.width = elementNode.style.height = 'auto';
                };

                GTBPreviewer.prototype.stripTextToOneLine = function(elementNode, width, height){
                    width = Math.floor(width);
                    elementNode.style.width = width + 'px';
                    elementNode.style.overflow = "hidden";

                    var lineNode = elementNode.firstChild
                    var original_data = lineNode.data;
                    lineNode.data = 'jJ';
                    var lineHeight = elementNode.scrollHeight * 1.5;
                    if (('undefined' != typeof height) && (height > lineHeight)) {//if height been set means multiple lines
                        lineHeight = Math.floor(height);
                    }
                    lineNode.data = original_data;
                    while((lineNode.data.length > 3) && ((elementNode.scrollWidth > width) || (elementNode.scrollHeight > lineHeight))) {
                        lineNode.data = lineNode.data.substr(0, lineNode.data.length - 3).replace(/\S\s*$/, '...');
                    }

                    elementNode.style.overflow = 'visible';
                    elementNode.style.width = elementNode.style.height = 'auto';
                };

                GTBPreviewer.prototype.tidyHeight = function(componentName){
                    var maxHeight = 0;
                    var paddingVertical = 0;
                    for (var i = 0; i < this.cells; ++i) {
                        var component = this.adCells[i][componentName];
                        component.style.padding = GTBPreviewer.LINE_SPACING + 'px 0px';
                        maxHeight = Math.max(maxHeight, component.offsetHeight);
                    }
                    if (1 < this.headCell.colSpan) {
                        for (var i = 0; i < this.cells; ++i) {
                            var component = this.adCells[i][componentName];
                            paddingVertical = GTBPreviewer.LINE_SPACING + Math.floor((maxHeight - component.offsetHeight) / 2);
                            component.style.padding = paddingVertical + 'px 0px';
                        }
                    }
                };

                //Handles the gtb ads XML response
                GTBPreviewer.prototype.handleXML = function(XMLDoc){
                    var getDataByTagName = function(entry, tagName){
                        var e = entry.getElementsByTagName(tagName)[0];
                        return e.firstChild ? e.firstChild.nodeValue : '';
                    };

                    var locationName = XMLDoc.getElementsByTagName('location');
                    if (0 < locationName.length) {
                        this.location.cityName = (locationName[0].firstChild) ? locationName[0].firstChild.nodeValue : '';
                        if (/^\s*$/.test(this.location.cityName)) {
                            this.location.cityName = 'Location';
                        }
                    }

                    this.location.nearbyCities = [];
                    var gtbEntries = XMLDoc.getElementsByTagName('entry');
                    var cellsCount = this.adCells.length < gtbEntries.length ? this.adCells.length : gtbEntries.length;
                    for (var i = 0; i < cellsCount; ++i) {
                        var adCell = this.adCells[i];

                        var imageSource = getDataByTagName(gtbEntries[i], 'image');
                        adCell.image.getElementsByTagName('img')[0].src = imageSource + this.baseURL + '&id=' + getDataByTagName(gtbEntries[i], 'id') +
                                '&width=' + this.imageSize.width + '&height=' + this.imageSize.height;
                        adCell.imageId = getDataByTagName(gtbEntries[i], 'id');
                        adCell.handle.bak = getDataByTagName(gtbEntries[i], 'handle');
                        adCell.handle.replaceChild(document.createTextNode(adCell.handle.bak), adCell.handle.firstChild);
                        adCell.age.bak = getDataByTagName(gtbEntries[i], 'age');
                        adCell.age.replaceChild(document.createTextNode(adCell.age.bak), adCell.age.firstChild);
                        adCell.city.bak = getDataByTagName(gtbEntries[i], 'city');
                        if (/^\s*$/.test(adCell.city.bak)) {
                            adCell.city.bak = 'Location';
                        }
                        this.location.nearbyCities[this.location.nearbyCities.length] = adCell.city.bak;
                        adCell.city.replaceChild(document.createTextNode(adCell.city.bak), adCell.city.firstChild);
                        adCell.headline.bak = getDataByTagName(gtbEntries[i], 'headline');
                        adCell.headline.replaceChild(document.createTextNode(adCell.headline.bak), adCell.headline.firstChild);
                    }

                    var city = (0 < this.location.nearbyCities.length) ?
                            this.location.nearbyCities[Math.floor(Math.random() * this.location.nearbyCities.length)] :
                            this.location.cityName;
                    this.adTitle.firstChild.data = this.adTitle.bak = this.title.replace(/\{city\}/ig, this.location.cityName).replace(/\{cities\}/ig, city);

                    this.updateSize();
                };

                // -- Utility --
                function createDiv(){
                    var div = document.createElement('div');
                    div.style.padding = '0px';
                    div.style.margin = '0px';
                    div.style.border = 'none';
                    div.style.backgroundColor = 'transparent';
                    return div;
                };

                // -- Ajax Utility --
                /**
                 * Constructor
                 * @param string url the url where the request is sent to
                 * @param string data the data to be sent to the server
                 * @param function listener the object which has function handleXML to accept the XML Document
                 */
                var AjaxRequest = function(url, data, listener){
                    var request = this.createRequest();
                    request.onreadystatechange = function () {
                        if ((4 == request.readyState) && (200 == request.status)) {
                            listener.handleXML(request.responseXML);
                            //alert(request.responseText); //check the response
                        }
                    };
                    this.request = request;
                    this.sendRequest(url, data);
                };

                AjaxRequest.prototype.createRequest = function(){
                    var request = null;
                    try {
                        request = new XMLHttpRequest();
                    }
                    catch (e) {//microsoft
                        try {
                            request = new ActiveXObject('Msxml2.XMLHTTP');
                        }
                        catch (e) {//other microsoft
                            try {
                                request = new ActiveXObject('Microsoft.XMLHTTP');
                            }
                            catch (e) {
                                request = null;
                            }
                        }
                    }

                    return request;
                };

                AjaxRequest.prototype.sendRequest = function(url, data){
                    this.request.open('POST', url, true);
                    this.request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                    this.request.send(data);
                };
                </script>
                                </td>
                                </tr>
                                <tr id="adText">
                                    &nbsp;
                                </tr>                           
                                </table>
                                </td>
                            </tr>
                            </table>
                        </td>
                        </tr>
                        </table>
                    </td>
                    </tr>
                    </table>
            </td>
        </tr>
        </table>
    </form>
        <!--END Edit Ads Space-->
    <!--</div>
    <div id="adCodeWeb">
        <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
        <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
        <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
    </div>

</div>
<!--END Tabs-->
<!--###############################################-->
